package com.yq.ylmall.product.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yq.ylmall.dto.product.ProductSpecQueryDto;
import com.yq.ylmall.model.product.ProductSpec;
import com.yq.ylmall.product.mapper.ProductSpecMapper;
import com.yq.ylmall.product.service.IProductSpecService;
import com.yq.ylmall.vo.product.ProductSpecPageVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品规格 服务实现类
 * </p>
 *
 * @author yzk789
 * @since 2024-05-30
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, ProductSpec> implements IProductSpecService {

    private final ProductSpecMapper productSpecMapper;

    @Override
    public IPage<ProductSpecPageVo> queryProductSpec(ProductSpecQueryDto dto) {
        IPage<ProductSpecPageVo> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        baseMapper.queryProductSpecPage(page, dto);
        return page;
    }

    @Override
    public void addProductSpec(ProductSpec dto) {
        productSpecMapper.insert(dto);
    }

    @Override
    public void removeProductSpec(Long id) {
        productSpecMapper.deleteById(id);
    }

    @Override
    public ProductSpecPageVo getProductSpecInfoById(long productSpecId) {
        return baseMapper.getProductSpecInfoById(productSpecId);
    }

    @Override
    public void updateProductSpecById(ProductSpec dto) {
        productSpecMapper.updateProductSpecById(dto);
    }

    @Override
    public IPage<ProductSpecPageVo> getProductSpecInfoByName(String specName) {
        IPage<ProductSpecPageVo> page = new Page<>();
        baseMapper.getProductSpecInfoByName(page,specName);
        return page;
    }


}
